const path = require('path')
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    target: "web",
    mode: "development",
    devtool: "source-map",
    entry: __dirname + '/js/main.js',
    output: {
      path: path.resolve(__dirname, "./build"),
      filename: "js/bundle.js",
    },
    // plugins: [
    //   new CleanWebpackPlugin(),
    //   new HtmlWebpackPlugin({
    //     template: "./public/index.html",
    //     title: "JavaScript工具"
    //   }),
    // ],
    devServer: {
        static: './', //本地服务器所加载的页面所在的目录
        host: '10.1.1.15', //本地IP地址
        historyApiFallback: true, //不跳转
        port: '3333', //端口号
        open: false,  // 启动打开浏览器
        proxy: {
          '/api': {
            target: 'https://sp0.baidu.com',  // 代理地址
            pathRewrite: {'^/api' : ''}, // 路径重写
            changeOrigin: true,     // target是域名的话，需要这个参数，
            secure: false,          // 设置支持https协议的代理
          },
    }
    },
    module: {
      rules: [
        {
          test: /\.css$/,
          use: ["style-loader", "css-loader", "postcss-loader"],
        },
        {
          test: /\.less$/,
          use: ["style-loader", "css-loader", "less-loader"],
        },
        {
          test: /\.(jpe?g|png|gif|svg)$/,
          type: "asset",
          generator: {
            filename: "img/[name]_[hash:6][ext]",
          },
          parser: {
            dataUrlCondition: {
              maxSize: 10 * 1024,
            },
          },
        },
        {
          test: /\.(eot|ttf|woff2?)$/,
          type: "asset/resource",
          generator: {
            filename: "font/[name]_[hash:6][ext]",
          },
        },
        {
          test: /\.js$/,
          loader: "babel-loader"
        },
        {
          test: /\.vue$/,
          loader: "vue-loader"
        }
      ],
    },
}